<script setup lang="ts">
  import { Field } from 'vee-validate';
  import { useLocale } from '@/locales/useLocale';
  const { t } = useLocale();
  const props = withDefaults(
    defineProps<{
      name: string;
      placeholder?: string;
      label?: string;
      requiredField?: boolean;
      size?: 'large' | 'small' | 'default';
      animateClass?: string;
    }>(),
    {
      name: 'default',
      placeholder: '',
      label: '',
      requiredField: false,
      size: 'default',
      animateClass: '',
    }
  );
</script>

<template>
  <Field :name="name" v-slot="{ value, field, errorMessage }">
    <el-form-item
      :error="errorMessage"
      :label="label && t(label)"
      :class="{ 'field-required': requiredField, [animateClass]: animateClass }"
      :size="size"
    >
      <el-input
        :placeholder="placeholder && t(placeholder)"
        v-bind="{ ...field, ...$attrs }"
        :model-value="value"
      />
    </el-form-item>
  </Field>
</template>

<style lang="scss">
  .field-required label {
    @apply before:content-['*'] before:mr-0.5 before:text-red-500;
  }
</style>
